@extends('layout.default')

@section('layout.content')

<div class="row">
    <div class="col-xs-12 align-right">
        <button class="btn btn-lg btn-primary create-category"><i class="ace-icon fa fa-columns"></i>新增门类</button>
        <button class="btn btn-lg btn-primary create-clase"><i class="ace-icon fa fa-table"></i>新增班级</button>
    </div>
  </div><!-- /.row -->

  <div class="row">
    <div class="col-xs-12">
      <h5 class="header blue" style="margin-top:-15px;">
        {{ $term->type->name }} > {{$term->name}}（{{ $term->branch->name }}）
      </h5>
      <table class="table table-hover table-striped table-bordered">
        <thead>
        <tr>
          <th class="align-middle" style="width: 100px;">门类</th>
          <th class="align-middle" style="width: 140px;">班级</th>
          <th class="center" style="width:50px;">计划招生</th>
          <th class="center" style="width:50px;">已报名</th>
          <th class="center" style="width:50px;">额满限招</th>
          <th class="center" style="width:50px;">入学考试</th>
          <th class="center" style="width:50px;">上交作品</th>
          <th class="align-middle" style="width: 320px;">招生/考试要求</th>
          <th class="align-middle" style="width: 80px;">上课时间</th>
        </tr>
        </thead>
        <tbody>
          @foreach ($categories as $category)
          <?php
            $count = count($category->clases);
            if($count <= 0) $count = 1;
            $rowspan = $count == 1 ? '' : "rowspan='{$count}'";
            $clase = $category->clases->shift();
          ?>
            <tr class="">
              <td class="align-middle category" {!! $rowspan !!}>
                {{ $category->name }}
                  <div class="pull-right operate">
                    <a href="javascript:;" class="blue edit-category" data-id="{{$category->id}}" data-category="{{$category}}" data-tid="{{$term->id}}"><i class="ace-icon fa fa-pencil"></i></a>
                    @if(count($category->clases)<=0)
                    <a href="javascript:;" class="red"><i class="ace-icon fa fa-times-circle"></i></a>
                    @endif
                  </div>
              </td>
              <td class="align-middle train" >
                @if(isset($clase))
                  {{ $clase->name }}
                  <div class="pull-right operate">
                    <a href="javascript:;"  class="blue edit-clase" data-id="{{$clase->id}}" data-tid="{{$term->id}}"><i class="ace-icon fa fa-pencil"></i></a>
                    @if(count($clase->users)<=0)
                    <a href="javascript:;" class="red"><i class="ace-icon fa fa-times-circle"></i></a>
                    @endif
                  </div>
                @endif
              </td>
              <td class="center" >{{ isset($clase)? $clase->number:'' }}</td>
              <td class="center" >{{ isset($clase)? count($clase->users):'' }}</td>
              <td class="center" >
                @if(isset($clase))
                {!! $clase->present()->isLimited() !!}
                @endif
              </td>
              <td class="center" >
                @if(isset($clase))
                {!! $clase->present()->isExam() !!}
                @endif
              </td>
              <td class="center" >
                @if(isset($clase))
                {!! $clase->present()->isHandin() !!}
                @endif
              </td>
              <td class="align-middle" >{{ isset($clase)? $clase->content:'' }}</td>
              <td class="align-middle" >{{ isset($clase)? $clase->classtime:'' }}</td>
            </tr>
            @if($rowspan != '')
              @foreach($category->clases as $clase)
              <tr class="train">
                <td class="align-middle train" >
                  {{ $clase->name }}
                  <div class="pull-right operate">
                    <a href="javascript:;"  class="blue edit-clase" data-id="{{$clase->id}}" data-tid="{{$term->id}}"><i class="ace-icon fa fa-pencil"></i></a>
                    @if(count($clase->users)<=0)
                    <a href="javascript:;" class="red"><i class="ace-icon fa fa-times-circle"></i></a>
                    @endif
                  </div>
                </td>
                <td class="center" >{{ $clase->number }}</td>
                <td class="center" >{{ count($clase->users) }}</td>
                <td class="center" >{!! $clase->present()->isLimited() !!}</td>
                <td class="center" >{!! $clase->present()->isExam() !!}</td>
                <td class="center" >{!! $clase->present()->isHandin() !!}</td>
                <td class="align-middle" >{{ $clase->content }}</td>
                <td class="align-middle" >{{ $clase->classtime }}</td>
              </tr>
              @endforeach
            @endif

          @endforeach
        </tbody>
      </table>
    </div>

  </div>

@stop

@section('javascript')

  <script src="//cdn.bootcss.com/jquery-validate/1.19.1/jquery.validate.min.js"></script>
  <script src="{{URL::asset('assets/js/jquery-validate-methods.js')}}"></script>
  <script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>

  <script type="text/javascript">
    $(function () {

      $('.create-category').on('click', function(e) {
        layer.open({
          type: 2,
          title: '新增课程',
          area: ['360px', '410px'],
          shade: 0.8,
          content: "{{route('train.category.create',$term->id)}}",
        });

      });


      $('.create-clase').on('click', function(e) {
        layer.open({
          type: 2,
          title: '新增班级',
          area: ['400px', '650px'],
          shade: 0.8,
          content: "{{route('train.clase.create',$term->id)}}",
        });

      });


      $('.edit-category').on('click', function(e) {
        var id = $(this).data('id');
        var tid = $(this).data('tid');
        var uri = "/train/category/"+id+"/edit";
        layer.open({
          type: 2,
          title: '修改门类名称',
          area: ['360px', '410px'],
          shade: 0.8,
          content: uri,
        });

      });


      $('.edit-clase').on('click', function(e) {
        var id = $(this).data('id');
        var tid = $(this).data('tid');
        var uri = "/train/clase/"+id+"/edit";
        layer.open({
          type: 2,
          title: '修改班级信息',
          area: ['400px', '650px'],
          shade: 0.8,
          content: uri,
        });

      });


      $('.train').on('mouseenter', function () {
          $(this).find('.operate').show();
      }).on('mouseleave', function () {
          $(this).find('.operate').hide();
      });


      $('.category').on('mouseenter', function () {
          $(this).find('.operate').show();
      }).on('mouseleave', function () {
          $(this).find('.operate').hide();
      });

    });
  </script>
@stop
